package com.example.changtest.ui

import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
import com.example.changtest.R
import com.example.changtest.ui.adapter.BliPageAdapter
import com.example.changtest.ui.view.BliConstraintLayout
import com.example.changtest.util.LogUtil

//https://www.jianshu.com/p/aa6770d29376
class D3Activity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_d3)

        val vPage = findViewById<ViewPager>(R.id.vpage)

        val mFragments: MutableList<Int> = ArrayList()
        mFragments.add(R.drawable.bg)
        mFragments.add(R.drawable.bg1)
        mFragments.add(R.drawable.bg2)
        mFragments.add(R.drawable.bg3)


        val pageAdapter = BliPageAdapter(this, mFragments)
        vPage.adapter = pageAdapter

        //变换
        vPage.setPageTransformer(false, BliPageTransformer())
    }
}

class BliPageTransformer : ViewPager.PageTransformer {
//    page : 当前子View
//    position：[-1 ,1]
//              position = -1 当前显示页的上一页。
//              position = 0 当前显示页。
//              position = 1 当前显示页的下一页。
    override fun transformPage(page: View, position: Float) {
        val bliConstraintLayout = page as BliConstraintLayout
        LogUtil.e("BliPageTransformer ${position}")
        /**
         * 倾斜度
         */
        val tiltDegree = 34
        val v = position * tiltDegree
        bliConstraintLayout.setRotateY(v)

        bliConstraintLayout.setIsLeftRotate(position > 0)
    }

}
